package com.lins.framework.utils;

import android.app.Activity;
import android.graphics.Color;
import android.os.Build;
import android.view.View;

/**
 * Created by LinS on 2016/11/25.
 */

public class WindowsUtil {
    /**
     * 隐藏状态栏
     */
    public static void setThisWindowsHide(Activity context) {
        View decorView = context.getWindow().getDecorView();
        int option = View.SYSTEM_UI_FLAG_FULLSCREEN;
        decorView.setSystemUiVisibility(option);

    }

    /**
     * 状态栏透明化
     */
    public static void setThisWindowsTransparent(Activity context) {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = context.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            context.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
    }

    /**
     * 透明化状态栏和导航栏
     */
    public static void setThisWindowsBarTransparent(Activity context) {
        if (Build.VERSION.SDK_INT >= 21) {
            View decorView = context.getWindow().getDecorView();
            int option = View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
            decorView.setSystemUiVisibility(option);
            context.getWindow().setNavigationBarColor(Color.TRANSPARENT);
            context.getWindow().setStatusBarColor(Color.TRANSPARENT);
        }
    }

    /**
     * 标准的沉浸式、重写onWindowFocusChanged
     *
     * @param hasFocus
     * @param context
     */
    public static void setThisWindowsImmersiveMode(boolean hasFocus, Activity context) {
        if (hasFocus && Build.VERSION.SDK_INT >= 19) {
            View decorView = context.getWindow().getDecorView();
            decorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_FULLSCREEN
                            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
        }
    }
}
